#include "LightMainWindow.h"
#include "QVBoxLayout"
#include <QSplitter>

#include "LightPresetModel.h"
#include "LightPresetFactory.h"
#include "LightFunctionFactory.h"
#include "lightControlGuiFactory.h"
#include "IF_lighttransitionengine.h"
#include "IF_LightEngineInterface.h"
#include "IF_GuiLightControlPanel.h"
#include "IF_DmxSliderPanel.h"
#include "ActionListView.h"
#include "ActionListController.h"

#include <LightPresetData.h>
#include <QList>


#define  NUMBER_OF_CHANNELS    6

QList<LightPresetData> BuiltInPresets = \
      QList<LightPresetData>() <<
   LightPresetData( QString("prova 1"),   3500, QList<double>()<<100.<<15.<<25.<<13.<<20.<<12.) <<
   LightPresetData( QString("prova 2"),   4500, QList<double>()<<20.<<100.<<10.<<20.<<13.<<11.) <<
   LightPresetData( QString("prova 3"),   1150, QList<double>()<<12.<<0.<<100.<<0.<<0.<<0.)     <<
   LightPresetData( QString("prova 4"),   3500, QList<double>()<<20.<<15.<<15.<<100.<<20.<<12.) <<
   LightPresetData( QString("prova 5"),   4500, QList<double>()<<9.<<9.<<9.<<9.<<95.<<9.)       <<
   LightPresetData( QString("prova 6"),   1150, QList<double>()<<20.<<10.<<0.<<10.<<0.<<100.)   <<
   LightPresetData( QString("prova 7"),   3500, QList<double>()<<20.<<15.<<75.<<53.<<40.<<12.)  <<
   LightPresetData( QString("prova 8"),   4500, QList<double>()<<0.<<5.<<9.<<10.<<12.<<0.)   <<
   LightPresetData( QString("prova 9"),   1150, QList<double>()<<30.<<35.<<39.<<0.<<0.<<0.)     <<
   LightPresetData( QString("prova 10"),  3500, QList<double>()<<0.<<8.<<11.<<20.<<30.<<40.)    <<
   LightPresetData( QString("prova 11"),  4500, QList<double>()<<30.<<40.<<50.<<60.<<80.<<91.)  <<
   LightPresetData( QString("prova 12"),  1150, QList<double>()<<89.<<90.<<98.<<99.<<100.<<0.);


MainWindow::MainWindow(QWidget *parent)
   : QMainWindow(parent)
{
   LightFunctionFactory *functionFactory = new LightFunctionFactory( this);
   LightPresetFactory *presetFactory = new LightPresetFactory( this);

   IF_LightTransitionEngine *transitionEngine = functionFactory->buildTransitionEngine( NUMBER_OF_CHANNELS);
   LightPresetModel *model = functionFactory->buildModel( NUMBER_OF_CHANNELS, *presetFactory);
   ActionListController *actionController = new ActionListController( *model, this);
   IF_LightEngineInterface *engine = functionFactory->buildLightEngine( *model, *transitionEngine,
                                                                        *actionController);

   QSplitter *splitter = new QSplitter( Qt::Vertical, this);
   setCentralWidget( splitter);

   LightControlGuiFactory *guiFactory = new LightControlGuiFactory( NUMBER_OF_CHANNELS, this);

   IF_DmxSliderPanel *sliderPanel = guiFactory->buildDmxSliderPanel( engine, transitionEngine, this);
   IF_GuiLightControlPanel *lightPanel = guiFactory->buildPresetListViewer( engine, model,
                                                                            actionController, this);

   splitter->setBackgroundRole( QPalette::Dark );
   splitter->addWidget( sliderPanel);
   splitter->addWidget( lightPanel);

   /* In tracer code some presets are created here. In real code, this is triggered by
    * a button or by opening a show file
    */
   for (int i=0; i < BuiltInPresets.length(); i++)
   {
      model->updatePreset( BuiltInPresets.at(i) );
   }
}

MainWindow::~MainWindow()
{
}

